Skip to content

FE-841: Pi agent foundations β€” in-process SDK, toolchain profiles#194

Merged
kostandinang merged 15 commits into
mainfrom
ka/fe-841-pi-sdk-embed
Jun 19, 2026
Merged

FE-841: Pi agent foundations β€” in-process SDK, toolchain profiles#194
kostandinang merged 15 commits into
mainfrom
ka/fe-841-pi-sdk-embed

Conversation

@kostandinang

@kostandinang kostandinang commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Stack Context

This is the foundation layer of the cook/brunch-serve stack. It establishes how the cook agent runs β€” embedded rather than shelled out β€” and how it targets a repo's test runner, so the brownfield-delivery and operational-hardening PRs above it can build on a stable agent runtime.

Consolidates two frontier items (FE-841, FE-843) into one PR.

What?

Embed pi as an in-process SDK (FE-841). Replace the external pi CLI dependency with an in-process SDK session β€” per-session cwd/tools, env-fed auth, no external install. Hardened with session guards, tightened timeouts and output caps, cleaned-up late setup timeouts, and pinned SDK patch levels (node floor + nested vulnerable patches).

Data-driven toolchain profiles (FE-843). A profile registry (node-vitest, node-test, node-jest, deno, …) replacing hardcoded toolchain assumptions. The architect classifies the profile from spec prose; selection precedence is flag ≫ spec ≫ bun, persisted into plan.yaml. Inherited profile names are rejected.

Why?

The cook agent previously depended on an external pi CLI and assumed a single toolchain. Neither is portable for autonomous brownfield delivery from a spec. Embedding the SDK removes an install-time dependency and gives per-session control; the data-driven profile registry lets the architect target the repo's real test runner instead of a hardcoded one.

Note: cook agent sandbox confinement (FE-853) was originally slated for this foundation but is un-integrated parallel work (it predates the data-driven profile refactor); it stays on its own branch/PR (#211) pending a dedicated integration.

@cursor

cursor Bot commented Jun 10, 2026

Copy link
Copy Markdown

PR Summary

High Risk
Changes the core cook LLM execution path (auth, timeouts, tool scoping) and introduces a large new dependency tree; unknown profile handling and architect fallbacks affect every plan/cook run.

Overview
Cook runs the coding agent in-process via @earendil-works/pi-coding-agent (0.79.8): runPi builds SDK sessions with sandbox cwd, comma-split tool allowlists (read-only for evaluate-done), ANTHROPIC_API_KEY-only auth in a per-run temp agent dir, buffered text_delta output (not stdout), and shared timeout/output-cap guards with abort on hang or overflow. The external pi CLI spawn path is removed.

Toolchain profiles are data-driven in project-profile.ts (bun, brunch, node-vitest, node-test, node-jest, deno). brunch plan accepts --profile=<id>; the emitter resolves flag ≫ spec profile ≫ architect-classified profile ≫ bun, stamps plan.profile on emitted YAML, and resolveToolchain throws on unknown ids at cook time (absent/empty still defaults to bun for fixtures). The build architect schema/prompt adds optional profile classification from spec prose only.

Docs (orchestration-guide.md) and planning notes reflect embedded cook + optional npx pi for plan translation. Node engine floor is >=22.19.0; lockfile adds the pi SDK tree and npm overrides for nested deps.

Reviewed by Cursor Bugbot for commit a565a73. Bugbot is set up for automated code reviews on this repo. Configure here.

@github-actions

github-actions Bot commented Jun 10, 2026

Copy link
Copy Markdown

Dependency Review

The following issues were found:

  • ❌ 1 vulnerable package(s)
  • βœ… 0 package(s) with incompatible licenses
  • βœ… 0 package(s) with invalid SPDX license definitions
  • βœ… 0 package(s) with unknown licenses.
  • ⚠️ 11 packages with OpenSSF Scorecard issues.

View full job summary

Comment thread src/orchestrator/src/pi-actions.ts Outdated
@kostandinang kostandinang force-pushed the ka/fe-841-pi-sdk-embed branch from 1b4e94a to 3e1665d Compare June 10, 2026 14:08
Comment thread src/orchestrator/src/pi-actions.ts Outdated
Comment thread src/orchestrator/src/pi-actions.ts Outdated

kostandinang commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Comment thread src/orchestrator/src/pi-actions.ts Outdated
@kostandinang kostandinang requested a review from lunelson June 10, 2026 17:06
Comment thread src/orchestrator/src/pi-actions.ts Outdated
Comment thread src/orchestrator/src/pi-actions.ts
lunelson
lunelson previously approved these changes Jun 11, 2026
kostandinang and others added 4 commits June 15, 2026 12:57
…endency

Replace the spawn('pi', …) subprocess in pi-actions.ts with an in-process
createAgentSession over @earendil-works/pi-coding-agent (pinned 0.79.1), so a
fresh checkout no longer needs an external pi binary on $PATH β€” only
ANTHROPIC_API_KEY.

- buildSessionOptions maps the old CLI flags to SDK config: tools allowlist,
  model-registry lookup, system-prompt override, in-memory session + empty
  resource overrides (no context files).
- Auth fed from brunch's own ANTHROPIC_API_KEY (no pi login / ~/.pi/auth.json);
  one reused per-process agent dir, no per-call temp leak.
- Output captured off text_delta events (never brunch's stdout, keeps the cook
  SSE stream clean); cooperative timeout + 10MB output cap.
- Read-only evaluator scoping (I126-K) preserved via the SDK tools allowlist;
  injectable SessionFactory keeps the drive loop offline-testable.
- Drops the `which pi` prereq from the cook guide (npx pi for the interim helper).
- Override transitive hono to 4.12.25 (patches the moderate advisories the
  dependency-review gate flags).
- PI_REAL_LLM-gated smoke proves a real in-process run with no pi on $PATH.

πŸ€– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread package.json Outdated
kostandinang and others added 6 commits June 17, 2026 09:33
Co-authored-by: Cursor <cursoragent@cursor.com>
…ard queue

Co-authored-by: Claude <noreply@anthropic.com>
…t/deno profiles

Profiles are now data literals (path templates + argv template + conventions
prose) compiled into the unchanged Toolchain interface β€” adding a runtime is
one data entry. Registry invariants pinned enumerably across all profiles.

Co-authored-by: Claude <noreply@anthropic.com>
…d into plan.yaml

brunch plan gains --profile=<id> (validated via parseProfileId); the emitter
resolves the chain once and stamps the id on both the authored and fallback
plans, so cook always reads the profile the emitter used. resolveToolchain
now throws UnknownProfileError on a typo'd id instead of silently running
bun; absent stays lenient for hand-authored fixtures.

Co-authored-by: Claude <noreply@anthropic.com>
architectPlan's schema gains an optional profile enum (registry ids,
null when the spec is silent); the emitter chain becomes flag ≫ spec
profile ≫ architect-classified ≫ bun. A hallucinated profile fails the
schema parse and rides the existing deterministic fallback. D160-K
intact β€” classification reads projected spec prose only.

Queue exhausted: CARDS.md retired; PLAN frontier marked branch-complete.

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@kostandinang kostandinang changed the title FE-841: Embed pi as an in-process SDK to drop the external pi CLI dependency FE-841: Pi agent foundations β€” in-process SDK, toolchain profiles Jun 18, 2026
lunelson
lunelson previously approved these changes Jun 19, 2026
pi-coding-agent 0.79.1 pinned undici 8.3.0, which trips three advisories
flagged by the dependency-review check (GHSA-38rv-x7px-6hhq,
GHSA-vmh5-mc38-953g, GHSA-pr7r-676h-xcf6). 0.79.8 is the first patch
release that depends on the fixed undici 8.5.0. A root override can't
reach the SDK's exact-pinned nested undici, so bump the SDK itself.
Comment thread src/orchestrator/src/pi-actions.ts
@kostandinang kostandinang self-assigned this Jun 19, 2026
Detect SDK-level assistant failures after prompt resolution so cook does not advance past a failed in-process agent run.

Co-authored-by: Cursor <cursoragent@cursor.com>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 29dd141. Configure here.

Comment thread src/orchestrator/src/project-profile.ts
Co-authored-by: Cursor <cursoragent@cursor.com>
@kostandinang kostandinang requested a review from lunelson June 19, 2026 15:09
@kostandinang kostandinang added this pull request to the merge queue Jun 19, 2026
Merged via the queue into main with commit 977ea9c Jun 19, 2026
6 checks passed
@kostandinang kostandinang deleted the ka/fe-841-pi-sdk-embed branch June 19, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants